package com.zl.learning.lambada.model;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by zhaolei on 2017/6/23.
 */
@Data
@NoArgsConstructor
public class Student implements Comparable<Student> {

    private int id;
    private String name;
    private int grade;
    private int classes;
    private double score;

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public Student(double score) {
        this.score = score;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Student that = (Student) o;
        if (id != that.id) {
            return false;
        }
        if (grade != that.grade) {
            return false;
        }
        if (classes != that.classes) {
            return false;
        }
        if (Double.compare(that.score, score) != 0) {
            return false;
        }
        return !(name != null ? !name.equals(that.name) : that.name != null);

    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + grade;
        result = 31 * result + classes;
        temp = Double.doubleToLongBits(score);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public int compareTo(Student o) {
        return this.id - o.id;
    }
}
